package core

import (
	"fmt"
	"server/apps"
	"server/apps/ods/ods_config"
	"server/apps/ods/ods_job"
	"server/apps/xidw/xidw_service"
	"time"

	"go.uber.org/zap"
	"server/global"
)

type server interface {
	ListenAndServe() error
}

func RunWindowsServer() {
	if global.SysDB != nil {
		xidw_service.InitJwtBlackList()
	}
	Router := apps.InitRouters()
	Router.Static("/form-generator", "./resource/page")

	address := fmt.Sprintf(":%d", global.XidwConfig.System.Addr)
	fmt.Printf("server port: %s\n", address)
	s := NewServerPort(address, Router)

	var j []ods_job.OdsJob
	err := global.SysDB.Find(&j).Error
	if err != nil {
		global.Logger.Info("获取任务列表失败:", zap.Error(err))
	}
	for _, t := range j {
		if t.Start == true && t.JobType == "定时同步" {
			ods_config.StartTmJob(t.ID)
		}
		if t.Start == true && t.JobType == "实时同步" {
			ods_config.StartRtJob(t.ID)
		}
	}

	time.Sleep(10 * time.Microsecond)
	global.Logger.Info("XIDW智能数据仓库启动成功:", zap.String("address", address))

	global.Logger.Error(s.ListenAndServe().Error())
}
